var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('/Users/jiangleivos/alibaba-work/DB/db');
var timeNow = new Date();
var fs = require('fs');
var path = '/Users/jiangleivos/alibaba-work/DB/candidate3.txt';


// var offStep = 2500;


function logTime(str) {
    console.log('----------------------------------------------------- ' + str + '   ', (new Date().getTime() - timeNow.getTime()) / 1000 + 'S');
}
function main (){
    logTime('main')
    var data = fs.readFileSync(path).toString();
    var keywordArr = data.split('\n');
    var sql = 'begin;'
    keywordArr.forEach(function(keyword) {
        if (keyword !== '') {
            sql += 'insert into tmp (keyword) values ("' + escape(keyword) + '");';
        }
    });
    sql += 'commit;'
    console.log('keywordNumber = '+keywordArr.length,sql.length);
    db.serialize(function(){
        db.exec(sql,function(err){
            if(!err){
                db.get('select count(*) as count from tmp',function(err,row){
                    if(!err){
                        console.log(row);
                    }else{
                        console.log(err);
                    }
                    logTime('end');
                });                
            }else{
                console.log(err);
            }

        });
    });
}
main();